/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */

/**
 * @param {ListNode} head
 * @return {boolean}
 */
var hasCycle = function (head) {
  const set = new Set();
  let length = 0;

  while (head !== null) {
    length++;
    if (!set.has(head)) {
      set.add(head);
    } else return true;
    head = head.next;
  }

  if (length === 1) return false;

  return false;
};
